﻿/**
* ObjectExt.js
* 
* @author Demis Bellot
* @version 1.0
* @requires Class.js
*
* Copyright 2009, Demis Bellot
* http://code.google.com/p/ajaxstack/
*/

function ObjectExt() { }
var O = ObjectExt;
O.keys = function(obj)
{
	var keys = [];
	for (var key in obj) keys.push(key);
	return keys;
}
O.values = function(obj)
{
	var values = [];
	for (var key in obj) values.push(obj[key]);
	return values;
}
O.count = function(obj) 
{
    var i = 0;
    for (var key in obj) i++;
    return i;
}
O.containsKey = function(obj, item)
{
	for (var key in obj) if (key == item) return true;
	return false;
}
O.containsValue = function(obj, item)
{
	for (var key in obj) if (obj[key] == item) return true;
	return false;
}
O.any = function(obj, mapFn)
{
	for (var key in obj) if (mapFn(key, obj[key])) return true;
	return false;
}
O.all = function(obj, mapFn)
{
	for (var key in obj) if (!mapFn(key, obj[key])) return false;
	return true;
}
O.isEmpty = function(o1)
{
	if (!o1) return true;
	for (var a in o1) return false;
	return true;
}
O.each = function(o, fn)
{
	for (var i in o) fn(i, o[i]);
}
O.merge = function(dst, src)
{
	for (var k in src) dst[k] = src[k];
	return dst;
}
O.clone = function(obj)
{
	var to = {};
	for (var key in obj) to[key] = obj[key];
	return to;
}
O.factoryFn = function()
{
	return {};
}
O.areEqual = function(obj, other) {
    if (!(is.Object(obj) && is.Object(other))) return false;

    for (var k in obj) {
        if (obj[k] != other[k]) return false;
    }
    for (var k in other) {
        if (obj[k] != other[k]) return false;
    }
    return true;
}
O.take = function(obj, count) {
    var to = {}, i = 0;
    for (var key in obj) {
        if (i++ < count)
            to[key] = obj[key];
        else break;
    }
    return to;
}
O.skip = function(obj, count) {
    var to = {}, i = 0;
    for (var key in obj) {
        if (i++ >= count)
            to[key] = obj[key];
    }
    return to;
}
O.where = function(obj, predicateFn) {
    var to = {};
    for (var key in obj)
        if (predicateFn(key, obj[key])) to[key] = obj[key];
    return to;
}
